import { fetchServiceTypeOptions} from '../../utils/request'
import Toast from 'tdesign-miniprogram/toast/index';
const image = 'https://tdesign.gtimg.com/miniprogram/images/example2.png';
Page({
  data: {
    imgSrcs: [
      "https://it00zyq.oss-cn-beijing.aliyuncs.com/b613cc0114fc47ebae3d99ace96ba5f4QQ截图20230414141751.png",
      "https://it00zyq.oss-cn-beijing.aliyuncs.com/306f50bc601b4dcbbfa2f3d35675dbb3QQ截图20230414141503.png",
      "https://it00zyq.oss-cn-beijing.aliyuncs.com/dc7e0b0264ff4ffa93443d61657f7650QQ截图20230414141623.png",
      "https://it00zyq.oss-cn-beijing.aliyuncs.com/feef648642c14291bc31f3a5cdca64beQQ截图20230414141751.png",
      "https://it00zyq.oss-cn-beijing.aliyuncs.com/54fbe2def79543d69ede5974274d9fc0微信截图_20230414141656.png"
    ],
    tabList: [],
    goodsList: [],
    goodsListLoadStatus: 0,
    pageLoading: false,
    current: 1,
    autoplay: true,
    duration: '500',
    interval: 5000,
    navigation: { type: 'dots' },
    essayName: '',
    content: ['有福智慧家政欢迎您！', 
    '人工客服24小时在线等候您的咨询！', 
    '您可通过需求匹配获得更合适的服务！'],
    categories: [
      {
        badgeProps: {},
        items: []
      },
    ],
    options: []
  },
  toDemand(e) {
    console.log("toDemand");
    wx.switchTab({
      url: '/pages/demand-form/demand-form',
    })
  },

  onShow() {
    this.getTabBar().init();
    this.init();
  },

  onLoad() {
    this.init();
  },

  async init() {
    const res = await fetchServiceTypeOptions();
    if (res) {
      const d = res.data;
      this.setData({
        categories: [
          {
            badgeProps: {},
            items: d.slice(0, d.length > 6 ? 6 : d.length)
          }
        ]
      })
      console.log(this.data.categories);
    }
  },

  async handleToHousekeeper(e) {
    const type = e.currentTarget.dataset.id;
    wx.setStorageSync('serviceType', type)
    wx.navigateTo({
      url: '/pages/shopping/shopping?type=' + type,
    })
  }
});
